#define _CRT_SECURE_NO_WARNINGS 1
#include "Book.h"
#include "Borrower.h"

void Menu()
{
    printf("***************************************************\n");
    printf("******     1.采编入库    2.展示书库图书    ********\n");
    printf("******     3.借阅        4.展示借阅者信息  ********\n");
    printf("******     5.归还        0.退出程序        ********\n");
    printf("***************************************************\n");
}

enum option
{
    EXIT,
    ADDBOOK,
    DLISTPRINT,
    BORROWBOOK,
    DLISTPRINT2,
    RETURNBOOK
};

int main()
{
    int input = 0;
    DLNode* pList = DListInit(); // 初始化的同时加载文件
    DLNode2* pList2 = BorrowertInit();
    do
    {
        Menu();
        printf("请选择：");
        scanf("%d", &input);
        switch (input)
        {
        case ADDBOOK:
            AddBook(pList);
            break;
        case DLISTPRINT:
            DListPrint(pList);
            break;
        case BORROWBOOK:
            BorrowBook(pList, pList2);
            break;
        case DLISTPRINT2:
            DListPrint2(pList2);
            break;
        case RETURNBOOK:
            ReturnBook(pList, pList2);
            break;
        case EXIT:
            SaveBook(pList); //退出时加载信息进文件并释放空间
            SaveBorrower(pList2);

            DListDestory(pList);
            DListDestory2(pList2);
            printf("已退出程序\n");
            break;
        default:
            printf("选择错误，重新选择\n");
            break;
        }
    } while (input);
    return 0;
}